import type { UploadImage } from "@/types/user";
import { defineStore } from "pinia";
import { ref } from "vue";

export interface ConsultInfo {
  illnessDesc: string;
  illnessTime: number;
  consultFlag: number;
  pictures: UploadImage[];
}

export const useConsultStore = defineStore(
  "consult",
  () => {
    const initData: ConsultInfo = {
      illnessDesc: "",
      illnessTime: 1,
      consultFlag: 0,
      pictures: [] as UploadImage[],
    };

    const illnessInfo = ref<ConsultInfo>({ ...initData });

    // 咨询类型
    const type = ref("");
    // 科室 id
    const depId = ref("");
    // 三甲 普通 医院类型
    const illnessType = ref("");
    // 患者id
    const patientId = ref("");

    // 清空 store
    const clear = () => {
      // 重置对象数据
      illnessInfo.value = { ...initData };
      // 重置普通数据
      type.value = "";
      depId.value = "";
      illnessType.value = "";
      patientId.value = "";
      uni.showToast({
        title: "清空成功",
        icon: "none",
        mask: true,
      });
    };
    return { illnessInfo, type, depId, illnessType, patientId, clear };
  },
  {
    unistorage: true,
  }
);
